Shortcut to model download

This is an open assessment looking at potential health effects of a national fish promotion program in Finland. The details of the assessment are described at Opasnet. This file contains the R code to run the assessment model.

This code downloads all the ovariables created by the previous code, fishhealth_initiate.Rmd, runs the model and plots various graphs and tables about the results.

objects.latest("Op_fi5932",code_name="initiate") # [[PFAS-yhdisteiden tautitaakka]]
## Loading objects:
##   ages
##   amount
##   amount_raw
##   amount_statistics
##   amountOrig
##   BF
##   binoptest
##   BoD
##   BoDattr
##   BoDattrOrig
##   BW
##   case_burden
##   Colamount
##   ColBoD
##   ColBoDattr
##   Colcase_burden
##   Colconc_pfas
##   Coldose
##   ColERF
##   Colexpo_dir
##   Colexpo_indir
##   Colexposure
##   ColPAF
##   Colthreshold
##   conc
##   conc_eukalat
##   conc_mehg
##   conc_pcddf
##   conc_pcddf_raw
##   conc_pfas
##   conc_pfas_raw
##   conc_vit
##   CTable
##   dat
##   dec
##   DecBoD
##   Decconc
##   Decconc_vit
##   Decincidence
##   df
##   dose
##   dummy
##   ERF
##   ERF_diox
##   ERF_env
##   ERF_mehg
##   ERF_micr
##   ERF_omega3
##   ERF_pfas
##   ERF_vit
##   ERFchoice
##   expand_index
##   expo_background
##   expo_dir
##   expo_indir
##   exposure
##   f_ing
##   f_mtoc
##   fish_proportion
##   frexposed
##   Hg
##   incidence
##   Inpamount
##   InpBoD
##   limits
##   mc2d
##   mc2dparam
##   opts
##   ovashapetest
##   P_illness
##   PAF
##   population
##   prepare
##   RR
##   RRorig
##   showind
##   showLoctable
##   subgrouping
##   sumExposcen
##   t0.5
##   TEF
##   TEFraw
##   TEFversion
##   tmp
##   total_amount
##   trim
##   wiki_username
if(!params$porvoo) {
  Decconc@dectable <- Decconc@dectable[Decconc@dectable$Option=="BAU",]
}

conc_eukalat <- EvalOutput(conc_eukalat)
BoDattr <- EvalOutput(BoDattr, verbose=TRUE)
##  Evaluating BoDattr ...
## - Evaluating BoD ...
## - - Evaluating incidence ...
## 
##  done(0 secs)!
## - - Checking incidence marginals ... Response, Age, incidenceSource recognized as marginal(s).
## - - Processing incidence decisions ... done!
## - - Evaluating case_burden ...
## 
##  done(0.01 secs)!
## - - Checking case_burden marginals ... Response, Gender, Iter, case_burdenSource recognized as marginal(s).
## - - Processing case_burden marginal collapses ...
## Warning in oapply(variable, FUN = fun[[i]], cols = cols[[i]], na.rm =
## TRUE): While oapplying case_burden, found NAs in indices: Gender. They were
## automatically filled using fillna, which may result in a multiplied population.
## Please check your ovariable before using oapply.
##  done!
## - - Evaluating population ...
## 
##  done(0.01 secs)!
## - - Checking population marginals ... Gender, Age, populationSource recognized as marginal(s).
## 
## - done(0.65 secs)!
## - Checking BoD marginals ... Response, Age, incidenceSource, Adjust, Gender, populationSource, Iter, BoDSource recognized as marginal(s).
## - Processing BoD inputs ... done!
## - Processing BoD marginal collapses ...
## Warning in oapply(variable, FUN = fun[[i]], cols = cols[[i]], na.rm = TRUE):
## While oapplying BoD, found NAs in indices: Adjust, InpBoDSource. They were
## automatically filled using fillna, which may result in a multiplied population.
## Please check your ovariable before using oapply.
##  done!
## - Processing BoD decisions ... done!
## - Evaluating PAF ...
## - - Evaluating dose ...
## - - - Evaluating exposure ...
## - - - - Evaluating expo_dir ...
## - - - - - Evaluating amount ...
## 
## ----- done(0.89 secs)!
## - - - - - Checking amount marginals ... Food, Iter, Group, Fish, Gender, fish_proportionSource, amountSource recognized as marginal(s).
## - - - - - Processing amount inputs ... done!
## - - - - - Processing amount marginal collapses ...
## Warning in oapply(variable, FUN = fun[[i]], cols = cols[[i]], na.rm =
## TRUE): While oapplying amount, found NAs in indices: Iter, Group, Gender,
## fish_proportionSource, Fishing. They were automatically filled using fillna,
## which may result in a multiplied population. Please check your ovariable before
## using oapply.
##  done!
## - - - - - Evaluating conc ...
## - - - - - - Evaluating conc_vit ...
## 
##  done(0.02 secs)!
## - - - - - - Checking conc_vit marginals ... Kala, Fish, Nutrient, Iter, conc_vitSource recognized as marginal(s).
## - - - - - - Processing conc_vit decisions ... done!
## - - - - - - Evaluating conc_pfas ...
## - - - - - - - Evaluating conc_pfas_raw ...
## 
##  done(0.09 secs)!
## - - - - - - - Checking conc_pfas_raw marginals ... Fish, Compound, Iter, conc_pfas_rawSource recognized as marginal(s).
## 
## ------ done(1.09 secs)!
## - - - - - - Checking conc_pfas marginals ... Fish, Compound, Iter, conc_pfas_rawSource, Area, conc_pfasSource recognized as marginal(s).
## - - - - - - Processing conc_pfas marginal collapses ... done!
## - - - - - - Evaluating conc_pcddf ...
## - - - - - - - Evaluating conc_pcddf_raw ...
## 
##  done(0 secs)!
## - - - - - - - Checking conc_pcddf_raw marginals ... ﮮTHL_code, Matrix, POP, Fish_species, Catch_site, Catch_location, Catch_date, Catch_season, Catch_square, N_individuals, Sample_type, Length_mean_mm, Weight_mean_g, Sex, Age, Fat_percentage, Dry_matter_percentage, conc_pcddf_rawSource recognized as marginal(s).
## - - - - - - - Evaluating TEF ...
## - - - - - - - - Evaluating TEFraw ...
## 
##  done(0 secs)!
## - - - - - - - - Checking TEFraw marginals ... Group, Compound, TEFversion, TEFrawSource recognized as marginal(s).
## 
## ------- done(0.06 secs)!
## - - - - - - - Checking TEF marginals ... Compound, Group, TEFversion, TEFrawSource, TEFSource recognized as marginal(s).
## 
## ------ done(0.2 secs)!
## - - - - - - Checking conc_pcddf marginals ... Fish, conc_pcddfSource recognized as marginal(s).
## - - - - - - Evaluating conc_mehg ...
## Warning in rnorm(openv$N, Hg$MeanLog[i], Hg$SDLog[i]): NAs produced
## Warning in rnorm(openv$N, Hg$MeanLog[i], Hg$SDLog[i]): NAs produced
## ------ done(0.47 secs)!
## - - - - - - Checking conc_mehg marginals ... Area, Kala, Iter, Fish, conc_mehgSource recognized as marginal(s).
## 
## ----- done(3.09 secs)!
## - - - - - Checking conc marginals ... Fish, Compound, Iter, concSource recognized as marginal(s).
## - - - - - Processing conc decisions ... done!
## - - - - - Evaluating expo_background ...
## 
##  done(0 secs)!
## - - - - - Checking expo_background marginals ... Exposure_agent, Gender, Iter, expo_backgroundSource recognized as marginal(s).
## 
## ---- done(43.08 secs)!
## - - - - Checking expo_dir marginals ... Fish, Iter, Group, Gender, fish_proportionSource, Fishing, Age, Exposure_agent, concSource, Exposcen, expo_dirSource recognized as marginal(s).
## - - - - Processing expo_dir marginal collapses ...
## Warning in oapply(variable, FUN = fun[[i]], cols = cols[[i]], na.rm = TRUE):
## While oapplying expo_dir, found NAs in indices: Fishing, Age, Exposcen. They
## were automatically filled using fillna, which may result in a multiplied
## population. Please check your ovariable before using oapply.
##  done!
## - - - - Evaluating expo_indir ...
## - - - - - Processing expo_dir marginal collapses ... done!
## - - - - - Evaluating t0.5 ...
## 
##  done(0 secs)!
## - - - - - Checking t0.5 marginals ... Exposure_agent, Iter, t0.5Source recognized as marginal(s).
## - - - - - Evaluating f_ing ...
## 
##  done(0 secs)!
## - - - - - Checking f_ing marginals ... Exposure_agent, Iter, f_ingSource recognized as marginal(s).
## - - - - - Evaluating f_mtoc ...
## 
##  done(0 secs)!
## - - - - - Checking f_mtoc marginals ... Exposure_agent, Iter, f_mtocSource recognized as marginal(s).
## - - - - - Evaluating BF ...
## 
##  done(0 secs)!
## - - - - - Checking BF marginals ... Exposure_agent, BFSource recognized as marginal(s).
## 
## ---- done(6.93 secs)!
## - - - - Checking expo_indir marginals ... Iter, Gender, Fishing, Age, Exposure_agent, Exposcen, expo_dirSource, f_ingSource, t0.5Source, f_mtocSource, BFSource, Exposure, expo_indirSource recognized as marginal(s).
## - - - - Processing expo_indir marginal collapses ... done!
## 
## --- done(1.44 mins)!
## - - - Checking exposure marginals ... Iter, Gender, Fishing, Age, Exposure_agent, Exposcen, Exposure, expo_dirSource, exposureSource recognized as marginal(s).
## - - - Processing exposure marginal collapses ...
## Warning in oapply(variable, FUN = fun[[i]], cols = cols[[i]], na.rm = TRUE):
## While oapplying exposure, found NAs in indices: Gender. They were automatically
## filled using fillna, which may result in a multiplied population. Please check
## your ovariable before using oapply.
##  done!
## - - - Evaluating BW ...
## 
##  done(0 secs)!
## - - - Checking BW marginals ... BWSource recognized as marginal(s).
## 
## -- done(1.52 mins)!
## - - Checking dose marginals ... Iter, Gender, Fishing, Age, Exposure_agent, Exposcen, Exposure, Scaling, exposureSource, BWSource, doseSource recognized as marginal(s).
## - - Processing dose marginal collapses ... done!
## - - Evaluating ERF ...
## - - - Evaluating ERF_env ...
## 
##  done(0.03 secs)!
## - - - Checking ERF_env marginals ... Exposure_agent, Response, Subgroup, Exposure, ER_function, Scaling, Exposure_unit, Observation, Iter, ERF_envSource recognized as marginal(s).
## - - - Evaluating ERF_omega3 ...
## 
##  done(0.02 secs)!
## - - - Checking ERF_omega3 marginals ... Exposure_agent, Response, Exposure, Exposure_unit, ER_function, Scaling, Observation, Iter, ERF_omega3Source recognized as marginal(s).
## - - - Evaluating ERF_mehg ...
## 
##  done(0 secs)!
## - - - Checking ERF_mehg marginals ... Exposure_agent, Response, Exposure, Exposure_unit, ER_function, Scaling, Observation, Iter, ERF_mehgSource recognized as marginal(s).
## - - - Evaluating ERF_diox ...
## 
##  done(0.01 secs)!
## - - - Checking ERF_diox marginals ... Exposure_agent, Response, Exposure, Exposure_unit, ER_function, Scaling, Observation, Iter, ERF_dioxSource recognized as marginal(s).
## - - - Evaluating ERF_vit ...
## 
##  done(0 secs)!
## - - - Checking ERF_vit marginals ... Exposure_agent, Response, Exposure, Exposure_unit, ER_function, Scaling, Observation, ERF_vitSource recognized as marginal(s).
## - - - Evaluating ERF_micr ...
## 
##  done(0 secs)!
## - - - Checking ERF_micr marginals ... Exposure_agent, Response, Exposure, Exposure_unit, ER_function, Scaling, Observation, ERF_micrSource recognized as marginal(s).
## - - - Evaluating ERF_pfas ...
## 
##  done(0 secs)!
## - - - Checking ERF_pfas marginals ... Exposure_agent, Response, Exposure, Exposure_unit, ER_function, Scaling, Observation, Iter, ERF_pfasSource recognized as marginal(s).
## - - - Evaluating ERFchoice ...
## 
##  done(0 secs)!
## - - - Checking ERFchoice marginals ... Exposure_agent, Response, Scaling, Exposure, ER_function, ERFchoiceSource recognized as marginal(s).
## 
## -- done(2.32 secs)!
## - - Checking ERF marginals ... Exposure_agent, Response, Exposure, ER_function, Scaling, Observation, Iter, ERFSource recognized as marginal(s).
## - - Processing ERF marginal collapses ... done!
## - - Evaluating RR ...
## - - - Processing dose marginal collapses ... done!
## - - - Processing ERF marginal collapses ... done!
## 
## -- done(1.06 mins)!
## - - Checking RR marginals ... Exposure_agent, Response, ER_function, Scaling, Iter, ERFSource, Gender, Fishing, Age, Exposcen, Exposure, doseSource, RRSource recognized as marginal(s).
## - - Evaluating frexposed ...
## 
##  done(0 secs)!
## - - Checking frexposed marginals ... frexposedSource recognized as marginal(s).
## - - Evaluating P_illness ...
## 
##  done(0 secs)!
## - - Checking P_illness marginals ... Response, Illness, Age, P_illnessSource recognized as marginal(s).
## 
## - done(3.85 mins)!
## - Checking PAF marginals ... Exposure_agent, Response, ER_function, Scaling, Iter, ERFSource, Gender, Fishing, Age, Exposcen, Exposure, doseSource, frexposedSource, incidenceSource, Adjust, RRSource, PAFSource recognized as marginal(s).
## - Processing PAF marginal collapses ...
## Warning in oapply(variable, FUN = fun[[i]], cols = cols[[i]], na.rm = TRUE):
## While oapplying PAF, found NAs in indices: Adjust. They were automatically
## filled using fillna, which may result in a multiplied population. Please check
## your ovariable before using oapply.
##  done!
## 
##  done(4.24 mins)!
##  Checking BoDattr marginals ... Adjust, Response, Age, Gender, Iter, Exposure_agent, Fishing, BoDattrSource recognized as marginal(s).
if(FALSE) {
oprint(summary(amount,"mean"))
oprint(summary(BoD,marginals=c("Age","Response"),"mean"))
oprint(summary(BoD,marginals=c("Gender","Response"),"mean"))
oprint(summary(BoDattr,marginals=c("Age","Response"),"mean"))
oprint(summary(BoDattr,marginals=c("Exposure_agent","Response"),"mean"))
oprint(summary(BoDattr,marginals=c("Gender","Response"),"mean"))
oprint(summary(case_burden,"mean"))
oprint(summary(conc,"mean"))
oprint(summary(dose,"mean"))
oprint(summary(ERF,"mean"))
oprint(summary(expo_dir,"mean"))
oprint(summary(expo_dir,marginals="Exposure_agent"))
oprint(summary(expo_indir,"mean"))
oprint(summary(exposure,"mean"))
#oprint(summary(fish_proportion,"mean"))
oprint(summary(incidence,"mean"))
oprint(summary(PAF,"mean"))
oprint(summary(population,"mean"))
oprint(summary(RR,"mean"))
}
###################
# Graphs
tmp <- trim(amount)
tmp <- tmp[tmp$Fishing!="Vanhankaupunginlahti",]
tmp$Group <- factor(tmp$Group, levels=c("Infants","Toddlers","Other children","Adolescents",
                                        "Adults", "Elderly"))

p <- ggplot(tmp, aes(x=Group, weight=amountResult, fill=Fish))+geom_bar()+
  coord_flip()+
  labs(
    title="Kalansyönti Suomessa ikäryhmittäin",
    y="Syönti (g/d)"
  )
  if(params$porvoo) {
    p <- p + facet_grid(Fishing ~ Gender)
    print(p)
    ggsave("Kalansyönti Suomessa ja Porvoossa ikäryhmittäin.svg")
  } else {
    p <- p + facet_grid(Gender~ .)
    print(p)
    ggsave("Kalansyönti Suomessa ikäryhmittäin.svg")
  }
## Saving 7 x 5 in image

plot_ly(trim(EvalOutput(total_amount)), x=~Kala, y=~total_amountResult, color=~Kala, type="bar") %>%
  layout(yaxis=list(title="Kalan kokonaiskulutus Suomessa (milj kg /a)"), barmode="stack")
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
ggplot(conc_mehg@output, aes(x=conc_mehgResult, colour=Area))+stat_ecdf()+
  scale_x_log10()+facet_wrap(~Fish, scales="free_x")

ggplot(trim(conc_pfas), aes(x=Fish, y=conc_pfasResult))+geom_point()+ # Inputed data for missing species.
  coord_flip()

ggplot(conc_pfas@output, aes(x=conc_pfasResult, color=Compound, linetype=Area))+stat_ecdf()+
  scale_x_log10()+
  stat_ecdf(data=conc_eukalat@output, aes(x=conc_eukalatResult))+
  scale_linetype_manual(values=c("dotted","solid","twodash"))+
  labs(
    title="PFAS concentration in fish in Finland",
    x="PFAS concentration (ng/g fresh weight)",
    y="Cumulative probability"
  )
## Warning in self$trans$transform(x): NaNs produced
## Warning: Transformation introduced infinite values in continuous x-axis
## Warning: Removed 16 rows containing non-finite values (stat_ecdf).

# The code may produce some negative values, which are removed from the graph
ggsave("PFAS-pitoisuus kalassa Suomessa.svg")
## Saving 7 x 5 in image
## Warning in self$trans$transform(x): NaNs produced
## Warning: Transformation introduced infinite values in continuous x-axis
## Warning: Removed 16 rows containing non-finite values (stat_ecdf).
ggplot(conc@output, aes(x=concResult, colour=Fish))+stat_ecdf()+
  facet_wrap(~Compound, scales="free_x")

limits <- data.frame(
  Exposure_agent = c("TEQ","MeHg","PFAS","Vitamin D"),
  Type = c("TDI","TDI","TDI","RDI"),
  Result = c(2*70/7, 1.3*70/7,4.4*70/7,10)
)

tmp <- EvalOutput(expo_dir, verbose=TRUE) # Calculated again because we want Group which is collapsed
##  Evaluating expo_dir ...
## - Processing amount inputs ...
## Warning in ComputeDependencies(variable@dependencies, fillna = fillna, indent =
## indent + : Input checking amount failed! Error: undefined columns selected
## - Processing amount marginal collapses ... done!
## 
##  done(26.64 secs)!
##  Checking expo_dir marginals ... Fish, Iter, Group, Gender, fish_proportionSource, Fishing, Age, Exposure_agent, concSource, Exposcen, expo_dirSource recognized as marginal(s).
tmp <- oapply(tmp,NULL,sum,c("Fish","fish_proportionSource","amountSource","concSource"))
## Warning in oapply(tmp, NULL, sum, c("Fish", "fish_proportionSource",
## "amountSource", : While oapplying expo_dir, found NAs in indices: Group,
## Fishing, Age, Exposcen. They were automatically filled using fillna, which may
## result in a multiplied population. Please check your ovariable before using
## oapply.
tmp <- tmp[tmp$Exposcen=="BAU" & !tmp$Exposure_agent %in% c("ALA", "EPA"),]
tmp$Group <- factor(tmp$Group, levels=c("Toddlers","Other children","Adolescents","Adults","Elderly"))
if(params$porvoo) {
  tmp <- tmp[tmp$Exposure_agent=="PFAS",] 
  limits <- limits[limits$Exposure_agent=="PFAS",]
  titl <- "PFAS-yhdisteiden saanti kalasta eri ryhmissä"
} else titl <- "Yhdisteiden saanti kalasta"
p <- ggplot(tmp@output, aes(x=expo_dirResult+0.5, colour=Group))+stat_ecdf()+
  scale_x_log10()+
  geom_vline(data=limits, aes(xintercept=Result, linetype=Type))+
  geom_point(data = oapply(tmp,c("Group","Exposure_agent","Fishing"),mean)@output,
             aes(x=expo_dirResult, y=0.1), shape=1, size=3, stroke=2)+
  labs(title=titl,
       x="Suora altistuminen päivässä (kala: g, rasvahapot: mg, D-vit: ug, PFAS: ng, TEQ: pg)",
       y="kumulatiivinen todennäköisyys")
if(params$porvoo) {
  p <- p + facet_grid(Fishing ~ .)
  print(p)
  ggsave("PFAS-yhdisteiden saanti kalasta Suomessa ja Porvoossa.svg")
} else {
  p <- p + facet_wrap(~Exposure_agent, scales="free_x")
  print(p)
  ggsave("Yhdisteiden saanti kalasta Suomessa.svg")
}
## Saving 7 x 5 in image

ggplot(trim(oapply(exposure,NULL,mean,"Gender")), aes(x=Age, weight=exposureResult))+geom_bar()+
  facet_wrap(~Exposure_agent, scales="free_y")+
  labs(
    title="Exposure to compounds",
    y="(omega: mg/d; vit D: ug/d, PFAS: ng/d)"
  )

cat("Kalaperäisiä tautitaakkoja Suomessa\n")
## Kalaperäisiä tautitaakkoja Suomessa
if(openv$N>1) {
  tmp <- summary(ERF)
  tmp <- data.frame(
    Altiste = tmp$Exposure_agent,
    Vaikutus = tmp$Response,
    Annosvastefunktio = tmp$ER_function,
    Skaalaus = tmp$Scaling,
    Havainto = tmp$Observation,
    Keskiarvo = as.character(signif(tmp$mean,2)),
    "95 luottamusväli" = paste0(signif(tmp$Q0.025,2)," - ", signif(tmp$Q0.975,2)),
    Keskihajonta = signif(tmp$sd,2)
  )#[rev(match(lev, tmp$Exposure_agent)),]

  oprint(tmp)
  
  tmp <- summary(oapply(BoDattr,NULL,sum,c("Age","Gender","Response")))
  tmp <- data.frame(
    Altiste = tmp$Exposure_agent,
    Alue = tmp$Fishing,
    Keskiarvo = as.character(signif(tmp$mean,2)),
    "95 luottamusväli" = paste0(signif(tmp$Q0.025,2)," - ", signif(tmp$Q0.975,2)),
    Keskihajonta = signif(tmp$sd,2)
  )#[rev(match(lev, tmp$Exposure_agent)),]

  oprint(tmp)
  
  tmp <- summary(oapply(BoDattr,NULL,sum,c("Age","Gender","Exposure_agent")))
  tmp <- data.frame(
    Terveysvaikutus = tmp$Response,
    Alue = tmp$Fishing,
    Keskiarvo = signif(tmp$mean,2),
    "95 luottamusväli" = paste0(signif(tmp$Q0.025,2)," - ", signif(tmp$Q0.975,2)),
    Keskihajonta = signif(tmp$sd,2)
  )
  oprint(tmp)

  tmp <- summary(oapply(BoDattr,NULL,sum,c("Age","Gender","Exposure_agent","Response")))
  tmp <- data.frame(
    Terveysvaikutus = "Yhteensä",
    Alue = tmp$Fishing,
    Keskiarvo = signif(tmp$mean,2),
    "95 luottamusväli" = paste0(signif(tmp$Q0.025,2)," - ", signif(tmp$Q0.975,2)),
    Keskihajonta = signif(tmp$sd,2)
  )
  oprint(tmp)
}
##      Altiste                  Vaikutus Annosvastefunktio Skaalaus  Havainto
## 1        DHA Loss in child's IQ points               ERS     None       ERF
## 2        DHA Loss in child's IQ points               ERS     None Threshold
## 3       Fish       All-cause mortality                RR     None       ERF
## 4       Fish       All-cause mortality                RR     None Threshold
## 5       Fish                Depression                RR     None       ERF
## 6       Fish                Depression                RR     None Threshold
## 7       MeHg Loss in child's IQ points               ERS     None       ERF
## 8       MeHg Loss in child's IQ points               ERS     None Threshold
## 9     Omega3             Breast cancer                RR     None       ERF
## 10    Omega3             Breast cancer                RR     None Threshold
## 11    Omega3            CHD2 mortality     Relative Hill     None       ERF
## 12    Omega3            CHD2 mortality     Relative Hill     None Threshold
## 13      PFAS         Immunosuppression               ERS       BW       ERF
## 14      PFAS         Immunosuppression               ERS       BW Threshold
## 15       TEQ   Cancer morbidity yearly               CSF       BW       ERF
## 16       TEQ   Cancer morbidity yearly               CSF       BW Threshold
## 17       TEQ       Sperm concentration               ERS     None       ERF
## 18       TEQ       Sperm concentration               ERS     None Threshold
## 19       TEQ   Yes or no dental defect               ERS     None       ERF
## 20       TEQ   Yes or no dental defect               ERS     None Threshold
## 21 Vitamin D  Vitamin D recommendation              Step     None       ERF
## 22 Vitamin D  Vitamin D recommendation              Step     None Threshold
##    Keskiarvo  X95.luottamusväli Keskihajonta
## 1    -0.0013 -0.0018 - -0.00081      2.6e-04
## 2          0              0 - 0      0.0e+00
## 3          1              1 - 1      4.8e-04
## 4          0              0 - 0      0.0e+00
## 5       0.99           0.99 - 1      1.7e-03
## 6          0              0 - 0      0.0e+00
## 7       0.69        0.022 - 1.4      3.7e-01
## 8        6.8          0.32 - 13      3.8e+00
## 9          1              1 - 1      2.7e-04
## 10         0              0 - 0      0.0e+00
## 11     -0.17     -0.25 - -0.098      4.1e-02
## 12        47            47 - 47      0.0e+00
## 13     0.024     0.0012 - 0.045      1.3e-02
## 14         0              0 - 0      0.0e+00
## 15   9.8e-06  4.5e-07 - 1.9e-05      5.8e-06
## 16         0              0 - 0      0.0e+00
## 17   6.1e-05 -1.9e-05 - 0.00014      3.9e-05
## 18         0              0 - 0      0.0e+00
## 19    0.0014   0.00032 - 0.0024      5.8e-04
## 20         0              0 - 0      0.0e+00
## 21       100          100 - 100      0.0e+00
## 22        10            10 - 10      0.0e+00
##     Altiste Alue Keskiarvo X95.luottamusväli Keskihajonta
## 1       DHA  BAU     -1400         -8800 - 0         2400
## 2      Fish  BAU    -56000       -250000 - 0        75000
## 3      MeHg  BAU       720          0 - 7900         3900
## 4    Omega3  BAU    -14000     -48000 - -1.4        15000
## 5      PFAS  BAU        13            0 - 79           22
## 6       TEQ  BAU      1600          0 - 9100         2600
## 7 Vitamin D  BAU     -2200        -20000 - 0         5000
##              Terveysvaikutus Alue Keskiarvo X95.luottamusväli Keskihajonta
## 1        All-cause mortality  BAU    -51000       -240000 - 0        70000
## 2              Breast cancer  BAU     -3500    -15000 - 0.014         4300
## 3    Cancer morbidity yearly  BAU      1200          0 - 8300         2500
## 4             CHD2 mortality  BAU    -10000     -39000 - -1.4        12000
## 5                 Depression  BAU     -5400    -23000 - -0.01         6300
## 6          Immunosuppression  BAU        13            0 - 79           22
## 7  Loss in child's IQ points  BAU      -700      -7300 - 4800         4200
## 8        Sperm concentration  BAU       150          0 - 1400          410
## 9   Vitamin D recommendation  BAU     -2200        -20000 - 0         5000
## 10   Yes or no dental defect  BAU       180          0 - 1300          440
##   Terveysvaikutus Alue Keskiarvo X95.luottamusväli Keskihajonta
## 1        Yhteensä  BAU    -72000      -3e+05 - 270        87000
tmp <- trim(BoDattr[BoDattr$Fishing=="BAU",])
ggplot(tmp, aes(x=Exposure_agent, weight=BoDattrResult, fill=Response))+geom_bar()+
  labs(
    title="Tautitaakka kalasta tekijöittäin",
    x="Kalassa oleva tekijä",
    y="Tautitaakka (DALY/a"
  )

ggsave("Tautitaakka kalasta tekijöittäin.svg")
## Saving 7 x 5 in image
ggplot(tmp, aes(x=Age, weight=BoDattrResult, fill=Response))+geom_bar(position="stack")+
  scale_x_discrete(breaks = levels(ages)[seq(1,length(ages),3)])+
  labs(
    title="Tautitaakka kalassa olevista tekijöistä",
    x="Ikäryhmä",
    y="Tautitaakka (DALY/a)"
  )

ggsave("Tautitaakka kalassa olevista tekijöistä.svg")
## Saving 7 x 5 in image
tmp <- trim(BoDattr / population * 1000)
p <- ggplot(tmp, aes(x=Age, weight=Result, fill=Response))+geom_bar(position="stack")+
  scale_x_discrete(breaks = levels(ages)[seq(1,length(ages),3)])+
  labs(
    title="Tautitaakka kalassa olevista tekijöistä per henkilö",
    x="Ikäryhmä",
    y="Tautitaakka (mDALY/hlö/a)"
  )
if(params$porvoo) {
  p <- p + facet_wrap(~Fishing)
  oprint(p)
  ggsave("Tautitaakka kalassa olevista tekijöistä per henkilö.svg")
}

################ Insight network
#gr <- scrape(type="assessment")
#objects.latest("Op_en3861", "makeGraph") # [[Insight network]]
#gr <- makeGraph(gr)
#export_graph(gr, "ruori.svg")
#render_graph(gr) # Does not work: Error in generate_dot(graph) : object 'attribute' not found
##################### Diagnostics
#objects.latest("Op_en6007", code_name="diagnostics")
#print(showLoctable())
#print(showind())
# Run all above

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.